#include "stdafx.h"
#include "CppUnitTest.h"
#include "PluginICProcSteps.h"

#include "DefSocketImageCurator.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace PluginICProcStepsTest
{		
	TEST_CLASS(PluginICProcStepsTest)
	{
		PluginICProcSteps *_PluginICProcSteps;

	public:
		TEST_METHOD_INITIALIZE(InitPluginICProcStepsTest)
		{
			_PluginICProcSteps = new PluginICProcSteps();
		}

		TEST_METHOD_CLEANUP(DeinitPluginICProcStepsTest)
		{
			if (_PluginICProcSteps != '\0')
				delete _PluginICProcSteps;
			_PluginICProcSteps = '\0';
		}
		
		TEST_METHOD(CreatePluginICProcStepsTest)
		{
			Assert::IsNotNull(_PluginICProcSteps);
		}

		TEST_METHOD(IMxPluginBaseTest)
		{
			IMxPluginBase *base = static_cast<IMxPluginBase *>(::CreateClassInstance("[invalid interface GUID]"));
			Assert::IsNull(base);

			base = static_cast<IMxPluginBase *>(::CreateClassInstance(IMxPluginBaseIID::GUID()));

			Assert::IsNotNull(base);
			Assert::AreEqual(IPluginICProcStepsIID::GUID(), base->GetInterfaceGUID());
			Assert::AreEqual(IPluginICProcStepsIID::Name(), base->GetInterfaceName());
	
			IMxPluginLibDetails *details = static_cast<IMxPluginLibDetails *>(base->Dynamic_cast(IMxPluginLibDetailsIID::GUID()));
			Assert::IsNotNull(details);
			Assert::AreEqual("DD721C26-1B5A-4271-8BBD-D12A7A0648F8", details->GetLibID());
			Assert::AreEqual(1L, details->DestroyPtr());
			details = '\0';

			IMxPluginBase *base2 = base;
			base->DuplicatePtr();
			Assert::AreEqual(1L, base2->DestroyPtr());
			base2 = '\0';

			Assert::IsNotNull(base);
			Assert::AreEqual(IPluginICProcStepsIID::GUID(), base->GetInterfaceGUID());
			Assert::AreEqual(IPluginICProcStepsIID::Name(), base->GetInterfaceName());
	
			Assert::AreEqual(0L, base->DestroyPtr());
			base = '\0';
		}

		TEST_METHOD(IMxPluginLibDetailsTest)
		{
			IMxPluginLibDetails *details = static_cast<IMxPluginLibDetails *>(::CreateClassInstance(IMxPluginLibDetailsIID::GUID()));

			Assert::IsNotNull(details);

			Assert::AreEqual("DD721C26-1B5A-4271-8BBD-D12A7A0648F8", details->GetLibID());
			Assert::AreEqual("PluginICProcSteps",details->GetLibName());
			Assert::AreEqual("1.0.0.2", details->GetLibVersion());
			Assert::AreEqual("MxPlugin from Image Curator - provides interface for Image Processing Steps", details->GetLibDescription());
			Assert::AreEqual("http://www.imagecurator.org", details->GetLibSupportSite());
			Assert::AreEqual(DefSocketImageCurator::SID(), details->GetSocketAppID());

			Assert::AreEqual("Maximodex Limited",details->GetLibOwnerName());
			Assert::AreEqual("Copyright (C) 2012 Maximodex Limited", details->GetLibCopyrightNotice());
	
			Assert::AreEqual("New BSD Licence", details->GetLibLicenseName());
			Assert::AreEqual("http://imagecurator.codeplex.com/license", details->GetLibLicenseURL());

			Assert::AreNotEqual(L"[invalidPathFilename]", details->GetLibPathFilename());

			Assert::AreEqual(0L, details->DestroyPtr());
			details = '\0';
		}

		TEST_METHOD(IPluginXmlLibTest)
		{
			IPluginICProcSteps *expt = static_cast<IPluginICProcSteps *>(::CreateClassInstance(IPluginICProcStepsIID::GUID()));

			Assert::IsNotNull(expt);

			Assert::AreEqual("DD721C26-1B5A-4271-8BBD-D12A7A0648F8", expt->GetLibID());

			Assert::AreEqual(0L, expt->DestroyPtr());
			expt = '\0';
		}


	};
}